#include <iostream>
#include <stdio.h>


// #include "stdafx.h"
#include <iostream>
#include <boost/function.hpp>
#include<boost/bind.hpp>

using namespace std;



//print
int print(int a) 
{ 
	cout << a <<endl; 
	return a; 
} 
 
class X{
public:
	X(){};
	int print(int a) 
	{ 
		cout << a <<endl; 
		return a; 
	} 
};


typedef boost::function<int(int a)> FuncPrint;
typedef void(*fun)(int);

void myfun(int data)
{
	printf("get data:%d\n",data);
}

int main(int argv, char**argc)
{
    printf("************  test hello zc!!!   **************\n");
    /* add test code! */
    //外部函数
	boost::function<int(int)>f = print;
	f(5);

	fun a = myfun;
	a(5);
 
	//类成员函数，通过bind绑定
	X x;
	FuncPrint f2 = bind(&X::print,&x,_1);
	f2(10);
	//类成员函数，通过bind绑定，直接调用函数
	bind(&X::print,&x,_1)(15);
 
	//函数赋值不合法时，抛出一个boost::bad_function_call异常
	try
	{
		boost::function<void(char *)> f3;
		f3("");
	}
	catch (boost::bad_function_call &ex)
	{
		cout<<ex.what()<<endl;
	}

    
    return 0;
}
